package com.zyl.movie;

//
//Source code recreated from a .class file by IntelliJ IDEA
//(powered by FernFlower decompiler)
//


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class UsersMoviesMapper extends Mapper<LongWritable, Text, Text, NullWritable> {
 private HashMap<String, String> movie_info = new HashMap();
 private String splitter = "";
 private String movie_secondPart = "";

 public UsersMoviesMapper() {
 }

 protected void setup(Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {
     Path[] DistributePaths = DistributedCache.getLocalCacheFiles(context.getConfiguration());
     this.splitter = context.getConfiguration().get("SPLITTER");
     String line = "";
     BufferedReader br = null;
     Path[] var8 = DistributePaths;
     int var7 = DistributePaths.length;

     for(int var6 = 0; var6 < var7; ++var6) {
         Path path = var8[var6];
         if (path.toString().endsWith("movies.dat")) {
             br = new BufferedReader(new FileReader(path.toString()));

             while((line = br.readLine()) != null) {
                 String movieID = line.split(this.splitter)[0];
                 String genres = line.split(this.splitter)[2];
                 this.movie_info.put(movieID, genres);
             }
         }
     }

 }

 protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {
     String[] val = value.toString().split(this.splitter);
     this.movie_secondPart = (String)this.movie_info.get(val[5]);
     if (this.movie_secondPart != null) {
         String result = value.toString() + this.splitter + this.movie_secondPart;
         context.write(new Text(result), NullWritable.get());
     }

 }
}
